package com.mck.controller;

import com.mck.entity.Result;
import com.mck.entity.Page;
import com.mck.service.PageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0.0
 * @Author mck
 * @Date 2025/4/13 下午3:29
 * @注释
 */

@RestController
@RequestMapping("/api/public/page")
@Slf4j
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 获取所有页面
     */
    @GetMapping
    public Result getPageList() {
        log.info("获取所有页面");

        List<Page> pageList = pageService.getPageList();
        return Result.success(pageList);
    }

    /**
     * 获取指定页面
     */
    @PostMapping
    public Result getPageListSpecific(@RequestBody Page data) {
        log.info("获取指定页面");

        List<Page> pageList = pageService.getPageListBySpecific(data);
        return Result.success(pageList);
    }

    /**
     * 添加页面
     */
    @PostMapping("/add")
    public Result addPage(@RequestBody Page data) {
        log.info("添加页面");

        pageService.addPage(data);
        return Result.success();
    }

    /**
     * 修改页面
     */
    @PutMapping
    public Result updatePage(@RequestBody Page data) {
        log.info("修改页面");

        pageService.updatePage(data);
        return Result.success();
    }

    /**
     * 删除页面
     */
    @DeleteMapping("/{id}")
    public Result deletePage(@PathVariable Integer id) {
        log.info("删除页面");

        pageService.deletePage(id);
        return Result.success();
    }
}
